home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / crbaloon.c < prev    next >
C/C++ Source or Header  |  2000-04-04  |  4KB  |  166 lines

  1. /***************************************************************************
  2.  
  3.   vidhrdw.c
  4.  
  5.   Functions to emulate the video hardware of the machine.
  6.  
  7. ***************************************************************************/
  8.  
  9. #include "driver.h"
  10. #include "vidhrdw/generic.h"
  11.  
  12. static int spritectrl[3];
  13. static int flipscreen;
  14.  
  15. int crbaloon_collision;
  16.  
  17. /***************************************************************************
  18.  
  19.   Convert the color PROMs into a more useable format.
  20.  
  21.   Crazy Balloon has no PROMs, the color code directly maps to a color:
  22.   all bits are inverted
  23.   bit 3 HALF (intensity)
  24.   bit 2 BLUE
  25.   bit 1 GREEN
  26.   bit 0 RED
  27.  
  28. ***************************************************************************/
  29. void crbaloon_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
  30. {
  31.     int i;
  32.     #define TOTAL_COLORS(gfxn) (Machine->gfx[gfxn]->total_colors * Machine->gfx[gfxn]->color_granularity)
  33.     #define COLOR(gfxn,offs) (colortable[Machine->drv->gfxdecodeinfo[gfxn].color_codes_start + offs])
  34.  
  35.  
  36.     for (i = 0;i < Machine->drv->total_colors;i++)
  37.     {
  38.         int intensity;
  39.  
  40.  
  41.         intensity = (~i & 0x08) ? 0xff : 0x55;
  42.  
  43.         /* red component */
  44.         *(palette++) = intensity * ((~i >> 0) & 1);
  45.         /* green component */
  46.         *(palette++) = intensity * ((~i >> 1) & 1);
  47.         /* blue component */
  48.         *(palette++) = intensity * ((~i >> 2) & 1);
  49.     }
  50.  
  51.     for (i = 0;i < TOTAL_COLORS(0);i += 2)
  52.     {
  53.         COLOR(0,i) = 15;        /* black background */
  54.         COLOR(0,i + 1) = i / 2;    /* colored foreground */
  55.     }
  56. }
  57.  
  58.  
  59.  
  60. WRITE_HANDLER( crbaloon_spritectrl_w )
  61. {
  62.     spritectrl[offset] = data;
  63. }
  64.  
  65.  
  66.  
  67. WRITE_HANDLER( crbaloon_flipscreen_w )
  68. {
  69.     if (flipscreen != (data & 1))
  70.     {
  71.         flipscreen = data & 1;
  72.         memset(dirtybuffer,1,videoram_size);
  73.     }
  74. }
  75.  
  76. /***************************************************************************
  77.  
  78.   Draw the game screen in the given osd_bitmap.
  79.   Do NOT call osd_update_display() from this function, it will be called by
  80.   the main emulation engine.
  81.  
  82.  ***************************************************************************/
  83.  
  84. void crbaloon_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  85. {
  86.     int offs,x,y;
  87.     int bx,by;
  88.  
  89.     /* for every character in the Video RAM, check if it has been modified */
  90.     /* since last time and update it accordingly. */
  91.     for (offs = videoram_size - 1;offs >= 0;offs--)
  92.     {
  93.         if (dirtybuffer[offs])
  94.         {
  95.             int sx,sy;
  96.  
  97.  
  98.             dirtybuffer[offs] = 0;
  99.  
  100.             sx = offs % 32;
  101.             sy = offs / 32;
  102.             if (flipscreen == 0)
  103.             {
  104.                 sx = 31 - sx;
  105.                 sy = 35 - sy;
  106.             }
  107.  
  108.             drawgfx(tmpbitmap,Machine->gfx[0],
  109.                     videoram[offs],
  110.                     colorram[offs] & 0x0f,
  111.                     flipscreen,flipscreen,
  112.                     8*sx,8*sy,
  113.                     &Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  114.         }
  115.     }
  116.  
  117.     /* copy the character mapped graphics */
  118.     copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  119.  
  120.  
  121.     /* Check Collision - Draw balloon in background colour, if no */
  122.     /* collision occured, bitmap will be same as tmpbitmap        */
  123.  
  124.     bx = spritectrl[1];
  125.     by = spritectrl[2];
  126.  
  127.     drawgfx(bitmap,Machine->gfx[1],
  128.             spritectrl[0] & 0x0f,
  129.             15,
  130.             0,0,
  131.             bx,by,
  132.             &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  133.  
  134.     crbaloon_collision = 0;
  135.  
  136.     for (x = bx; x < bx + Machine->gfx[1]->width; x++)
  137.     {
  138.         for (y = by; y < by + Machine->gfx[1]->height; y++)
  139.         {
  140.             if ((x < Machine->drv->visible_area.min_x) ||
  141.                 (x > Machine->drv->visible_area.max_x) ||
  142.                 (y < Machine->drv->visible_area.min_y) ||
  143.                 (y > Machine->drv->visible_area.max_y))
  144.             {
  145.                 continue;
  146.             }
  147.  
  148.             if (read_pixel(bitmap, x, y) != read_pixel(tmpbitmap, x, y))
  149.             {
  150.                 crbaloon_collision = -1;
  151.                 break;
  152.             }
  153.         }
  154.     }
  155.  
  156.  
  157.     /* actually draw the balloon */
  158.  
  159.     drawgfx(bitmap,Machine->gfx[1],
  160.             spritectrl[0] & 0x0f,
  161.             (spritectrl[0] & 0xf0) >> 4,
  162.             0,0,
  163.             bx,by,
  164.             &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  165. }
  166.